package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.mapper.UserMapper;
import com.itany.pojo.User;
import com.itany.service.UserService;
import com.itany.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Description: 类的描述
 * Author: SJY
 * Date: 2021/08/26 10:01
 * Version: 1.0 版本信息
 */
@Service
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRED)
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public PageInfo<User> findUserAll(Integer page, Integer rows,User user) {
        PageHelper.startPage(page, rows);
        List<User> list = null;
        list = userMapper.selectBy(user);
        PageInfo<User> info = new PageInfo<User>(list);
        return info;
    }

    public ActionResult updateUser(User user){
        ActionResult at = new ActionResult();
        try{
            userMapper.updateUser(user);
            at.setMsg("修改成功");
        }catch(Exception e){
            at.setStatus(0);
            at.setMsg("服务器内部出错");
        }
        return at;
    }


}
